<template>
  <div
    class='container'
  >
    <el-card class="box-card">
      <el-button
        class="button"
        icon="el-icon-edit"
        type="success"
        size="small"
        @click="addSubjects"
      >
        新增学科
      </el-button>
      <el-form :inline="true" label-width="90px">
        <el-form-item label="学科名称">
            <el-input placeholder="请输入" />
          </el-form-item>
        <el-form-item size="large">
          <el-button size="small" >清除</el-button>
          <el-button size="small" type="primary">搜索</el-button>
        </el-form-item>
      </el-form>
      <el-alert
        :title="'数据一共'+ directorysList.counts + '条'"
        type="info"
        show-icon
        class="record"
      >
      </el-alert>
      <my-table
        :table-props="{
          data: directorysList.items,
          border: true
        }"
        :columns="[
          { label: '序号', prop: 'index', width: 100, align: 'center' },
          { label: '所属学科', prop: 'subjectName', width: 200, align: 'center' },
          { label: '目录名称', prop: 'directoryName', width: 150, align: 'center' },
          { label: '创造者', prop: 'username', width: 150, align: 'center' },
          { label: '创造日期', prop: 'addDate', width: 150, align: 'center' },
          { label: '面试题数量', prop: 'totals', width: 300, align: 'center' },
          { label: '状态', prop: 'state', width: 300, align: 'center' },
          { label: '操作', slotName: 'operators', width: 300, align: 'center' }, // 带插槽
        ]"
        :pagination-props="{
          layout: 'total, pager',
          total: directorysList.counts
        }"
        :pagination-events="events"
      >
        <template v-slot:operators="scope">
          <el-button @click="forbid(scope.row)" type="text">{{ scope.row.state === '已禁用' ? '启用' : '禁用' }}</el-button>
          <el-button type="text" :disabled="scope.row.state === '已禁用' ? false : true ">修改</el-button>
          <el-button @click="deleteArticle(scope.row)" type="text" :disabled="scope.row.state === '已禁用' ? false : true ">删除</el-button>
        </template>
      </my-table>
    </el-card>
  </div>
</template>

<script>
import { mapState, mapActions } from 'vuex';
export default {
  data() {
    return {
      currentPage: 1,
      pageSize: 10,
      events: {
        'current-change': this.onCurrentPageChange
      },
    }
  },
  computed: {
    ...mapState('directorys', [
      'directorysList'
    ])
  },
  methods: {
    ...mapActions('directorys', [
      'updateDirectorysList'
    ]),
     onCurrentPageChange(currentPage) {
      this.currentPage = currentPage
      this.updateDirectorysList({
        page: this.currentPage,
        size: this.pageSize,
      });
    },
  },
  async created() {
    await this.updateDirectorysList({
      page: this.currentPage,
      size: this.pageSize,
    });
  },
}
</script>

<style scoped lang='scss'>
.button {
  float: right;
}
.record {
  margin-bottom: 12px;
}
</style>
